package cn.aresoft.framework.support.action;


import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import cn.aresoft.framework.plugins.pagination.ibatis.IbatisPage;
import cn.aresoft.framework.plugins.pagination.ibatis.IbatisPageService;


public abstract class BaseActionSupport extends BaseAction{
	

	//===========  分页 --> 开始  ==============
	@Autowired
	@Qualifier("ibatisPageServiceImpl")
	private IbatisPageService ibatisPageService;

	/**
	 * Ibatis分页器装载
	 * @param sql
	 * @return
	 * @throws Exception
	 */
	public List findForSubListI(String sqlName, Serializable arg) throws Exception{
		
		IbatisPage pageBean = new IbatisPage();
		String jumpPage = request.getParameter("jumpPage");
		String pageSize = request.getParameter("pageSize");
		
		if (jumpPage != null && !"".equals(jumpPage) && pageSize != null && !"".equals(pageSize)) {
			pageBean.setPageSize(new Integer(pageSize));
		} else {
			jumpPage = "1";
		}
		pageBean.setPage(new Integer(jumpPage));
		
		// 设置记录的总页数
		pageBean.setCount(ibatisPageService.tableCountNum(sqlName + "Count", arg));
		getRequest().setAttribute("paginator", pageBean.getToolsMenu());
		
		return ibatisPageService.findForSubList(sqlName, arg, pageBean);
	}
	
	//===========  分页 --> 结束 ==============
	
	
}
